<template>
  <div class="Home">
    <el-container class="home_contatiner">
      <el-header class="home_header">
        <div class="header_div">
          <img src="../assets/logo2.jpg" />
          <div>
            <el-button type="primary">消息</el-button>
            <el-button type="success">设置</el-button>
            <el-button type="info" @click="logout">
              安全退出
              <i class="el-icon-caret-bottom"></i
            ></el-button>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <p class="uname">当前用户：{{ uname }}</p>
          <el-menu
            class="el-menu-vertical-demo"
            background-color="#FFFFFF"
            text-color="#1897D8"
            active-text-color="#1897D8"
            :default-active="selectPath"
            unique-opened
            router
          >
            <el-submenu :index="v.path" v-for="(v, index) in menusList" :key="v.id">
              <template slot="title">
                <i :class="icons[index].iname"></i>
                <span class="title_span">{{ v.authName }}</span>
              </template>
              <el-menu-item
                :index="item.path"
                v-for="item in v.children"
                :key="item.id"
                @click="select(item.path)"
                >{{ item.authName }}</el-menu-item
              >
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  name: "home",
  data() {
    return {
      uname: "users",
      menusList: [],
      selectPath: "",
      icons: [
        { iname: "iconfont icon-yonghuguanli" },
        { iname: "iconfont icon-quanxianguanli" },
        { iname: "iconfont icon-shangpinguanli" },
        { iname: "iconfont icon-dingdanguanli" },
        { iname: "iconfont icon-shujutongji" },
      ],
    };
  },
  methods: {
    async getMenus() {
      var p1 = await this.axios.get("menus");
      this.menusList = p1.data.data;
      console.log(p1);
    },
    select(path) {
      console.log(path);
      this.selectPath = path;
      sessionStorage.setItem("selectPath", path);
    },
    logout() {
      sessionStorage.removeItem("token");
      this.$router.push("/Login");
    },
  },
  mounted() {
    this.selectPath = sessionStorage.getItem("selectPath") || "users";
    this.uname = sessionStorage.getItem("uname");
    this.getMenus();
  },
};
</script>
<style lang="scss">
body,
html {
  height: 100%;
}
.Home {
  height: 100%;
  .home_contatiner {
    height: 100%;
  }
  .uname {
    line-height: 50px;
  }
}
.title_span {
  margin-left: 10px;
}
.home_header {
  background: #1897d8 !important;
  height: 80px !important;
}
.header_div {
  width: 100%;
  height: 100%;
  align-items: center;
  display: flex;
  justify-content: space-between;
  button {
    width: 150px;
  }
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #eeeeee;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  // line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
